import Vue from 'vue'
import Vuex from 'vuex'
import persistedstate from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:'',
    userInfo:{
      id:'',
      username:'',
    }
  },
  getters: {
  },
  mutations: {
    //更新token
    updateToken(state,newToken){
      console.log(12,state.token)
      state.token = newToken
    },
    // 更新用户信息
    updateUserInfo(state,newId){
      state.userInfo = newId
    }
  },
  actions: {
    //获取用户信息
    async getUserInfo(){

    }
  },
  modules: {
  },
  plugins:[
    persistedstate({
      storage: window.localStorage,
      key:'memory',
      reducer(val) {
        return {
          // 只储存state中的assessmentData
          token: val.token,
          userInfo:val.userInfo
        }
      }
    })
  ]
})
